package com.aierkeji.b2c.filter;

import java.io.IOException;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.aierkeji.b2c.utils.GsonUtils;
import com.aierkeji.b2c.utils.ResultMapHelper;
import com.aierkeji.b2c.utils.StringUtils;

@WebFilter(urlPatterns = { "/center/*" })
public class AkjCenterFilter implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest httpServletRequest = (HttpServletRequest) request;
		HttpServletResponse httpServletResponse = (HttpServletResponse) response;
		String userId = (String) httpServletRequest.getSession().getAttribute("userId");
		String lifeId = (String) httpServletRequest.getSession().getAttribute("lifeId");
		if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(lifeId)) {
			Map<String, Object> map = ResultMapHelper.nullParamsResult();
			response.getWriter().write(GsonUtils.parseToJson(map));
			return;
		}
		chain.doFilter(httpServletRequest, httpServletResponse);

	}

}
